import request from '@/utils/executor'

export function getAppDetail(app_id, user_id = null) {
  return request({
    url: `/executor/${app_id}`,
    method: 'get',
    params: user_id ? { user_id } : undefined
  })
}

export function executeAppStep(detail) {
  return request({
    url: `/executor_api`,
    method: 'post',
    headers: {
      'Content-Type': 'application/json'
    },
    data: detail
  })
}

export function getExecutroMemoryBus() {
  return request({
    url: `/executor/memory_bus`,
    method: 'get'
  })
}

export function processOutput(app_id) {
  return request({
    url: `/executor/process_output/${app_id}`,
    method: 'get'
  })
}

export function getLogList(params) {
  return request({
    url: `/executor/applogs`,
    method: 'get',
    params
  })
}

export function uploadFile(file, onUploadProgress) {
  return request({
    url: '/executor/file',
    method: 'post',
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    data: file,
    onUploadProgress
  })
}

export function downloadFile() {
  return request({
    url: '/executor/downloads',
    method: 'get',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8'
    }
  })
}

export function app_api(id, param) {
  return request({
    url: `/app_api/${id}`,
    method: 'post',
    headers: {
      'Content-Type': 'application/json'
    },
    data: param
  })
}
